﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace StudyLock2
{

    internal class Program
    {
        static int counter = 0;
        static readonly Object lockobject = new Object();
        private static Mutex mutex = new Mutex();
        static void Main(string[] args)
        {

            System.Threading.Timer t1 = new Timer(updatetimer,null,Timeout.Infinite,1000);
            t1.Change(0, 500);
            t1.Change(-1, 500);

            Thread[] thread = new Thread[3];
            for (int i = 0; i < 3; i++)
            {
                thread[i] = new Thread(ThreadMethod1);//方法引用
                thread[i].Name = "Thread-" + (i + 1).ToString();
            }
            for (int i = 0; i < 3; i++)
            {
                thread[i].Start();
            }
            Console.ReadKey();
        }

        private static void updatetimer(object state)
        {
            throw new NotImplementedException();
        }

        public static void ThreadMethod1(object val)
        {
          //  mutex.WaitOne();    //获取锁
            for (int i = 1; i <= 5; i++)
            {
                Console.WriteLine("{0}循環了{1}次", Thread.CurrentThread.Name, i);
            }
         //   mutex.ReleaseMutex();  //释放锁
        }
    }
}
